<template>
    <div class="home-goods-row">
        <div class="title">
            <h3>{{ goodsRowData.titleConfig.title }}</h3>
            <p>
                {{ goodsRowData.titleConfig.linkText }}
                <van-icon name="arrow" />
            </p>
        </div>
        <div class="goods-box">
            <ul class="goods-ul">
                <li
                    class="goods-li"
                    v-for="(item, i) in goodsList"
                    :key="i"
                >
                    <img :src="item.images" alt="">
                    <h5 class="title">{{ item.skuTitle }}</h5>
                    <div class="price">
                        <strong>¥{{ item.discountPrice | toFix }}</strong>
                        <span>¥{{ item.originalPrice | toFix }}</span>
                    </div>
                    <div
                        class="tag"
                        v-if="item.promotionList"
                    >
                        <img :src="tagBgImg(item.promotionList[0].type)" alt="">
                        <span>{{ item.promotionList[0].tag }}</span>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
export default {
    name: 'homeGoodsRow',
    props: ['goodsRowData'],
    data () {
        return {
            goodsList: null
        }
    },
    created () {
        // console.log(this.goodsRowData)
        this.goodsList = this.goodsRowData.skuInfo
    },
    methods: {
        tagBgImg (type) {
            if (type === 5) {
                return require('@/assets/img/home/tag-bg-5.png')
            } else if (type === 9) {
                return require('@/assets/img/home/tag-bg-9.png')
            } else if (type === 13) {
                return require('@/assets/img/home/tag-bg-13.png')
            } else if (type === -1) {
                return require('@/assets/img/home/tag-bg-13.png')
            } else {
                return require('@/assets/img/home/tag-bg-5.png')
            }
        }
    }
}
</script>

<style lang="scss">
.home-goods-row {
    padding: 10px 0;
    .title {
        padding: 0 25px 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        h3 {
            font-size: 16px;
            color: #666;
            font-weight: bold;
        }
        p {
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #999;
            font-size: 14px;
            font-weight: bold;
        }
    }
    .goods-box {
        overflow-x: auto;
        padding: 0 12px;
        .goods-ul {
            display: flex;
            flex-wrap: nowrap;
            .goods-li {
                float: left;
                margin-right: 6px;
                flex-shrink: 0;
                flex-grow: 0;
                width: 100px;
                background-color: #f9f9f9;
                border-radius: 7px;
                position: relative;
                > img {
                    display: block;
                    padding: 5px;
                    box-sizing: border-box;
                    width: 100%;
                }
                .title {
                    padding: 0 10px;
                    font-size: 10px;
                    color: #333;
                    line-height: 12px;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                }
                .price {
                    font-size: 9px;
                    font-weight: bold;
                    padding: 10px;
                    strong {
                        color: #c73734;
                    }
                    span {
                        color: #999;
                        text-decoration: line-through;
                        margin-left: 5px;
                    }
                }
                .tag {
                    width: 24px;
                    height: 24px;
                    position: absolute;
                    top: 5px;
                    right: 5px;
                    img {
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        top: 0;
                        right: 0;
                        z-index: 1;
                    }
                    span {
                        display: block;
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        top: 0;
                        left: 0;
                        z-index: 2;
                        font-size: 8px;
                        color: #fff;
                        text-align: center;
                        line-height: 24px;
                    }
                }
            }
        }
    }
}
</style>
